num1 = 10#全局变量


def demo1():
    print(f"num1={num1}地址为{id(num1)}")
    num2 = 5  # 优先用局部变量
    print(f"num2={num2}")
    # print(num3)


# num2 = 20  # 在入口之前即可
# demo1()
# num3 = 30  # 不可以放在函数入口下面

def demo2():
    """
    修改全局变量
    :return:
    """
    global num1
    num1 = 5

num1 = 10
print(f"修改全局变量前num1 = {num1},地址为{id(num1)}")
demo2()
print(f"修改全局变量后num1 = {num1},地址为{id(num1)}")